var Yingxiong = {
    
    
    
    run: function(creep) {
        room = Game.rooms['E19N2'];
        var fangzi=Game.getObjectById('6145f00e66eb27a686693517');
        var guanzi=Game.getObjectById('611ff64f66eb2781b35d2f47');
        var gongchang=Game.getObjectById('6135eb9f94d216ec7df91c7f');
        var lab0=Game.getObjectById('612a5069daf9fd35be7380e6');
        var lab1=Game.getObjectById('6145d895033753120a6378f3');
        var bianliang1=0;
        var bianliang2=0;
        if(creep.name=='人类高质量男性')
        {
            creep.usePower(PWR_GENERATE_OPS);
            time1=creep.ticksToLive;
            if(time1<500)
            {
                if(creep.renew(fangzi)==ERR_NOT_IN_RANGE)
                {
                    creep.moveTo(fangzi, {visualizePathStyle: {stroke: '#ffaa00'}});return;
                }
            }
            
            
            //工厂升级
            if(gongchang.effects[0]==undefined && (gongchang.store.getUsedCapacity(RESOURCE_CELL)>=1000 || gongchang.store.getUsedCapacity(RESOURCE_ALLOY)>=1000) )
            {
                bianliang1=PWR_OPERATE_FACTORY;
                bianliang2=gongchang;
            }
            //加快烧power
            if(fangzi.effects[0]==undefined && Game.creeps['烧'])
            {
                bianliang1=PWR_OPERATE_POWER;
                bianliang2=fangzi;
            }
            //lab加速
            if(Game.time % 5 ==0 && lab0.mineralType != undefined && lab1.mineralType != undefined)
            {
                let aa=[];
                let bb = [];
                aa.length=0;
                room.memory.labjiasu=[];//lab加速
                room.memory.labjiasu.length=0;
                const cc = room.find(FIND_STRUCTURES, {
                filter: (structure) => {
                return (structure.structureType == STRUCTURE_LAB ) && structure.effects[0]==undefined
                && structure!=lab0 && structure!=lab1
                }});
                for (let structure of cc) 
                {
                    bb.push(structure.id);//改find要记得改这里id
                }
                room.memory.labjiasu=bb;
                
                //console.log(labtime(room));
                //console.log(labtime(Game.rooms['E19N3']));
                
                
            }//console.log(Object.keys(Game.constructionSites));
            
            if(room.memory.labjiasu.length)
            var labjiasu=Game.getObjectById(room.memory.labjiasu[0]);
            if(labjiasu==null && room.memory.labjiasu.length!=0)
            {
                room.memory.labjiasu.shift();
                labjiasu=Game.getObjectById(room.memory.labjiasu[0]);
            }
            if(labjiasu) {
                bianliang1=PWR_OPERATE_LAB;
                bianliang2=labjiasu;
            }
            //console.log(gongchang.effects[0]);
            //console.log(bianliang1);
            //console.log(bianliang2);
            //console.log(room.memory.labjiasu.length);
            
        
            //console.log(JSON.stringify(lab0.effects));
            //console.log(lab0.effects[0].effect);
            
            
            //加罐子容量
            if(guanzi.effects[0]==undefined && guanzi.store.getUsedCapacity()>970000)
            {
                bianliang1=PWR_OPERATE_STORAGE;
                bianliang2=guanzi;
            }
            
            
            if(bianliang1 && bianliang2)
            {
                if(creep.store.getUsedCapacity(RESOURCE_OPS)<150 && creep.withdraw(guanzi,RESOURCE_OPS,1000-creep.store.getUsedCapacity(RESOURCE_OPS))==ERR_NOT_IN_RANGE)
                {
                    creep.moveTo(guanzi, {visualizePathStyle: {stroke: '#ffaa00'}});return;
                }
                if(creep.usePower(bianliang1,bianliang2)==ERR_NOT_IN_RANGE)
                {
                    creep.moveTo(bianliang2, {visualizePathStyle: {stroke: '#ffaa00'}});return;
                }
            }
            
            
            
            
            /*if(creep.store.getFreeCapacity() == 0 && creep.transfer(guanzi,RESOURCE_OPS)==ERR_NOT_IN_RANGE)
            {
                creep.moveTo(guanzi, {visualizePathStyle: {stroke: '#ffaa00'}});return;
            }*/
            /*if(creep.enableRoom(Game.getObjectById('5bbcae0a9099fc012e63859b'))==ERR_NOT_IN_RANGE)
            {
                creep.moveTo(Game.getObjectById('5bbcae0a9099fc012e63859b'));
            }*/
            if(Game.time%10==0)
            {
                creep.moveTo(41,20);
            }
        }
    }
    
    /*function labtime(room) {
        let time1=[];
        time1.length=0;
        const time0 = room.find(FIND_STRUCTURES, {
        filter: (structure) => {
        return (structure.structureType == STRUCTURE_LAB ) && structure.effects[0]!=undefined
        }});
        for (let structure of time0) 
        {
            time1.push(structure.effects[0].ticksRemaining);
        }
        console.log(time1);
        time1.sort((a,b) => a - b);
        console.log(time1);
    }*/
};
function labtime(room) {
        let time1=[];
        time1.length=0;
        const time0 = room.find(FIND_STRUCTURES, {
        filter: (structure) => {
        return (structure.structureType == STRUCTURE_LAB ) 
        && structure.effects!=undefined
        && structure.effects[0]!=undefined
        }});
        for (let structure of time0) 
        {
            time1.push(structure.effects[0].ticksRemaining);
        }
        time1.sort((a,b) => a - b);
        console.log(time1);
        return time1[0];
    }
module.exports = Yingxiong;

